package generator.website;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import website.*;

public class WebSiteResourcesPropertiesFactory
{
  protected static String nl;
  public static synchronized WebSiteResourcesPropertiesFactory create(String lineSeparator)
  {
    nl = lineSeparator;
    WebSiteResourcesPropertiesFactory result = new WebSiteResourcesPropertiesFactory();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "errors.header=<UL>" + NL + "" + NL + "errors.prefix=<LI><span>" + NL + "" + NL + "errors.suffix=</span></LI>" + NL + "" + NL + "errors.footer=</UL>" + NL;
  protected final String TEXT_2 = NL;
  protected final String TEXT_3 = ".title=";
  protected final String TEXT_4 = NL;
  protected final String TEXT_5 = NL;
  protected final String TEXT_6 = ".";
  protected final String TEXT_7 = "=";
  protected final String TEXT_8 = NL;
  protected final String TEXT_9 = NL;
  protected final String TEXT_10 = ".";
  protected final String TEXT_11 = ".error.required=La date doit avoir le pageFormat suivant : jj-mm-aaaa !" + NL;
  protected final String TEXT_12 = NL;
  protected final String TEXT_13 = ".";
  protected final String TEXT_14 = ".error.required=L'adresse email est invalide !" + NL;
  protected final String TEXT_15 = NL;
  protected final String TEXT_16 = ".";
  protected final String TEXT_17 = ".error.required=Le champ ";
  protected final String TEXT_18 = " est obligatoire !" + NL;
  protected final String TEXT_19 = NL;
  protected final String TEXT_20 = ".";
  protected final String TEXT_21 = "=";
  protected final String TEXT_22 = NL + "\t\t\t\t\t\t";
  protected final String TEXT_23 = NL;
  protected final String TEXT_24 = ".";
  protected final String TEXT_25 = ".";
  protected final String TEXT_26 = "=";
  protected final String TEXT_27 = NL + "\t\t\t\t\t\t\t";
  protected final String TEXT_28 = NL;
  protected final String TEXT_29 = ".";
  protected final String TEXT_30 = ".";
  protected final String TEXT_31 = "=";
  protected final String TEXT_32 = NL + "\t\t\t\t\t\t\t";
  protected final String TEXT_33 = NL;
  protected final String TEXT_34 = ".";
  protected final String TEXT_35 = "=";
  protected final String TEXT_36 = NL + "\t\t\t\t\t\t";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    EList<Page> pages = (EList<Page>)argument;
for(Page page : pages){

    stringBuffer.append(TEXT_2);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_3);
    stringBuffer.append(page.getTitle());
    stringBuffer.append(TEXT_4);
    
	EList<PageTag> pageTags = page.getPageTags();
	for(PageTag pageTag : pageTags){

    stringBuffer.append(TEXT_5);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(pageTag.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(pageTag.getText());
    stringBuffer.append(TEXT_8);
    
	}
	EList<Form> pageForms = page.getForms();
		for(Form pageForm : pageForms){
			EList<Tag> tags = pageForm.getTags();
				for(Tag tag : tags){
					if(tag instanceof FormTag && ((FormTag) tag).isRequired()){
						if(tag instanceof Date){

    stringBuffer.append(TEXT_9);
    stringBuffer.append(pageForm.getType().getName());
    stringBuffer.append(pageForm.getEntity().getName());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_11);
    						
						} else if(tag instanceof TextBox && ((TextBox)tag).getType() == TextType.getByName("email")){

    stringBuffer.append(TEXT_12);
    stringBuffer.append(pageForm.getType().getName());
    stringBuffer.append(pageForm.getEntity().getName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_14);
    						
						} else {

    stringBuffer.append(TEXT_15);
    stringBuffer.append(pageForm.getType().getName());
    stringBuffer.append(pageForm.getEntity().getName());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_17);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_18);
    					
						}
					}
					if(tag instanceof Button) {
						Button button = (Button) tag;

    stringBuffer.append(TEXT_19);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_20);
    stringBuffer.append(button.getName());
    stringBuffer.append(TEXT_21);
    stringBuffer.append(button.getText());
    stringBuffer.append(TEXT_22);
    
					} else if(tag instanceof RadioButton) {
						RadioButton radioButton = (RadioButton) tag;
						EList<Element> elements = radioButton.getElements();
						for(Element element : elements){

    stringBuffer.append(TEXT_23);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_24);
    stringBuffer.append(radioButton.getName());
    stringBuffer.append(TEXT_25);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_26);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_27);
    							
						}
					} else if(tag instanceof Select) {
						Select select = (Select) tag;
						EList<Element> elements = select.getElements();
						for(Element element : elements){

    stringBuffer.append(TEXT_28);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_29);
    stringBuffer.append(select.getName());
    stringBuffer.append(TEXT_30);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_31);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_32);
    							
						} 
					} else if(tag instanceof PageTag && !(tag instanceof Image)) {
						PageTag pageTag = (PageTag) tag;

    stringBuffer.append(TEXT_33);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_34);
    stringBuffer.append(pageTag.getName());
    stringBuffer.append(TEXT_35);
    stringBuffer.append(pageTag.getText());
    stringBuffer.append(TEXT_36);
    							
					}
				}				
			}
		}

    return stringBuffer.toString();
  }
}
